<?php

namespace app\dc\controller;

use app\common\model\Dc;
use think\Controller;
use think\Db;

class Index extends Base
{

    /**
     * 供应中心首页
     * HYF
     * @return mixed
     */
    public function index()
    {
        $dcm = new Dc();
        $name = $dcm->where('id', $this->dc_id)->value('name');
        $this->assign('name', $name);
        return $this->fetch();
    }


    public function console()
    {
        return $this->fetch();
    }


    /**
     * 数据统计
     * @return \think\response\Json
     */
    public function total()
    {


        $biz = Db::name('biz')->count();
        $dc = Db::name('dc')->count();
        $order = Db::name('order')->count();
        $order_goods = Db::name('goodslist')->count();
        return json(['biz' => $biz, 'dc' => $dc, 'order' => $order, 'order_goods' => $order_goods]);

    }


    /**
     * 近期订单
     * @return \think\response\Json
     */
    public function get_order_count()
    {

        $order = Db::name('order');
        $now_time_str = date('Y-m-d', time());
        $now_time = strtotime($now_time_str);
        $list = [];
        for ($i = 10; $i > 0; $i--) {
            $time = $now_time - $i * 86400;

            $order_count = $order
                // ->where('dc_id', $this->dc_id)
                ->where('createtime', '>', $time)
                ->where('createtime', '<', $time + 86400)
                ->count();
            $list['date'][] = date('n月j日', $time);
            if ($order_count) {
                $list['count'][] = $order_count;
            } else {
                $list['count'][] = 0;
            }

        }
        return json(['data' => $list]);


    }
}
